package com.mycompany.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Sql {

    static final String DRIVER_CLASS = "org.h2.Driver";//driver,warning:case sensitive 
    static final String JDBC_URL = "jdbc:h2:tcp://localhost/D:/h2/b";
    static final String USER = "zyk";//username
    static final String PASSWORD = "zyk"; //password
    
    
      public static String show(String a) throws Exception {
        Class.forName(DRIVER_CLASS);//load driver
        Connection conn = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
        Statement stmt = conn.createStatement();// createһ��Statement�  
        ResultSet rs = stmt.executeQuery("select * from stu_info where student_id=" + "'" + a + "'");
        String ss;
        
        if (rs.next()) {
            ss =rs.getString("student_id") + "\t" + rs.getString("name") + "\t" + rs.getString("sex") + "\t" + rs.getString("Escore") + "\t" + rs.getString("Mscore") + "\t" + rs.getString("Cscore");
            return ss;
        }
        else return null;
        
       
    }
    

    public static int compl(String a, String b) throws Exception {
        Class.forName(DRIVER_CLASS);//load driver
        //On the base of URL user password connect SQL
        Connection conn = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
        Statement stmt = conn.createStatement();// createһ��Statement�
        // stmt.executeUpdate("select id from stu_manage where name="+a);
        ResultSet rs = stmt.executeQuery("select * from stu_manage where student_id=" + "'" + a + "'");
        
        if (rs.next()) {
            String str = rs.getString("password");
            if (str.equals(b)) {

                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
        

    }

  

    static void p(String a) {
        System.out.println(a);
    }//display 
    //id VARCHAR(36) PRIMARY KEY,name VARCHAR(100),sex VARCHAR(4),student_id VARCHAR(50),Escore VARCHAR(50),Mscore VARCHAR(50),Cscore
//    private static void show(Statement stmt) throws SQLException{
//     ResultSet rs = stmt.executeQuery("SELECT * FROM stu_info");
//        while (rs.next()) {
//          p(rs.getString(1) + "\t" + rs.getString("name") + "\t" + rs.getString("sex")+"\t"+rs.getString(4));
//        }
//    }
//    String str ="";
//    public int compl(String a,String b){
//         if(str.equals(a)){
//             return 1;
//         }
//         else 
//         return 0;
//    }
//   
}
